const { Sequelize } = require('sequelize');

const sequelize = new Sequelize('master', 'sa', 'Kdvssqlserver123', {
  host: '10.11.3.90',
  port: 1433,
  dialect: 'mssql',
  dialectOptions: {
    encrypt: true, // 如果需要加密
    options: {
      trustServerCertificate: true, // 对于自签名证书
      cryptoCredentialsDetails: {
        minVersion: 'TLSv1' // 根据需要指定最低的 TLS 版本，SQL Server 2014 支持 TLS 1.0 或更高版本
        // minVersion: 'TLSv1.2' // 根据需要指定最低的 TLS 版本，SQL Server 2014 支持 TLS 1.0 或更高版本
      }
    }
  }
});

(async function () {
  try {
    await sequelize.authenticate();
    console.log('Connection has been established successfully.');
    // 关闭连接
    sequelize.close();
  } catch (error) {
    console.error('Unable to connect to the database:', error);
  }
})();
